package com.ssm.controller;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.ssm.pojo.Emp;
import com.ssm.service.EmpService;

@Controller
public class EmpControler {
	
	@Autowired
	private EmpService empService;
	
	@RequestMapping("/list")
	public String saveList(Model model){
		List<Emp> emps = new ArrayList<>();
		Emp emp1 = new Emp("xhcx", "jsdh");
		Emp emp2 = new Emp("张三", "java");
		Emp emp3 = new Emp("x", "jsdh");
		Emp emp4 = new Emp("李四", "c");
		Emp emp5 = new Emp("小哈", "java");
		Emp emp6 = new Emp("张思", "java");
		emps.add(emp1);
		emps.add(emp2);
		emps.add(emp3);
		emps.add(emp4);
		emps.add(emp5);
		emps.add(emp6);
		try {
			empService.saveEmpListService(emps);
			model.addAttribute("msg", "success");
		} catch (Exception e) {
			e.printStackTrace();
			model.addAttribute("msg", "error");
		}
		return "index";
	}
	@RequestMapping("/emp")
	public String saveEmp(Model model){
		Emp emp1 = new Emp("xhcx", "jsdh");
		try {
			empService.saveEmp(emp1);
			model.addAttribute("msg", "success");
		} catch (Exception e) {
			e.printStackTrace();
			model.addAttribute("msg", "error");
		}
		return "index";
	}
}
